package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mobile.domain.LessonPrescription;
import com.ruoyi.mobile.model.bo.LessonPrescriptionBo;
import com.ruoyi.mobile.model.request.LessonPrescriptionRequest;
import com.ruoyi.mobile.service.ILessonPrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 运动处方配置Controller
 * 
 * @author ruoyi
 * @date 2022-10-14
 */
@RestController
@RequestMapping("/mobile/prescription")
public class LessonPrescriptionController extends BaseController
{
    @Autowired
    private ILessonPrescriptionService lessonPrescriptionService;

    /**
     * 查询运动处方配置列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:prescription:list')")
    @GetMapping("/list")
    public TableDataInfo list(LessonPrescription lessonPrescription)
    {
        startPage();
        List<LessonPrescriptionBo> list = lessonPrescriptionService.selectLessonPrescriptionList(lessonPrescription);
        return getDataTable(list);
    }


    /**
     * 获取运动处方配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('mobile:prescription:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(lessonPrescriptionService.selectLessonPrescriptionById(id));
    }

    /**
     * 新增运动处方配置
     */
    @PreAuthorize("@ss.hasPermi('mobile:prescription:add')")
    @Log(title = "运动处方配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LessonPrescriptionRequest lessonPrescriptionRequest)
    {
        return toAjax(lessonPrescriptionService.insertLessonPrescription(lessonPrescriptionRequest));
    }

    /**
     * 修改运动处方配置
     */
    @PreAuthorize("@ss.hasPermi('mobile:prescription:edit')")
    @Log(title = "运动处方配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LessonPrescriptionRequest lessonPrescriptionRequest)
    {
        return toAjax(lessonPrescriptionService.updateLessonPrescription(lessonPrescriptionRequest));
    }

    /**
     * 删除运动处方配置
     */
    @PreAuthorize("@ss.hasPermi('mobile:prescription:remove')")
    @Log(title = "运动处方配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(lessonPrescriptionService.deleteLessonPrescriptionByIds(ids));
    }


    /**
     * 获取某一周次的运动处方配置详细信息
     */
    @GetMapping(value = "/week/{week}")
    public AjaxResult getInfoByWeek(@PathVariable("week") Integer week) {
        return AjaxResult.success(lessonPrescriptionService.selectLessonPrescriptionByWeek(week));
    }


    /**
     * 获取某一周次的运动处方配置详细信息
     */
    @GetMapping(value = "/all")
    public AjaxResult getAllWeek() {
        return AjaxResult.success(lessonPrescriptionService.selectAllWeek());
    }
}
